合成控制法、断点回归、倾向匹配得分代码合集 您所在的位置:网站首页 stata scc install 合成控制法、断点回归、倾向匹配得分代码合集

合成控制法、断点回归、倾向匹配得分代码合集

#合成控制法、断点回归、倾向匹配得分代码合集| 来源: 网络整理| 查看: 265

Example 1 - Construct synthetic control group:synth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975),trunit(3) trperiod(1989)

In this example, the unit affected by the intervention is unit no 3 (California) in the year 1989. Thedonor pool (since no counit is specified) defaults to the control units 1,2,4,5,...,39 ( ie. the other38 states in the dataset). Since no xperiod is provided, the predictor variables for which novariable specific time period is specified (retprice, lnincome, and age15to24) are averaged over theentire pre-intervention period up to the year of the intervention (1970,1981,...,1988). The beervariable has the time period (1984(1)1988) specified, meaning that it is averaged for the periods1984,1985,...,1988. The variable cigsale will be used three times as a predictor using the values fromperiods 1988, 1980, and 1975 respectively. The MSPE is minimized over the entire pretreatment period,because mspeperiod is not provided. By default, results are displayed for the period from1970,1971,...,2000 period (the earliest and latest year in the dataset).

Example 2 - Construct synthetic control group:synth cigsale beer lnincome(1980&1985) retprice cigsale(1988) cigsale(1980) cigsale(1975), trunit(3)trperiod(1989) fig

This example is similar to example 1, but now beer is averaged over the entire pretreatment period whilelnincome is only averaged over the periods 1980 and 1985. Since no data is available for beer prior to1984, synth will inform the user that there is missing data for this variable and that the missingvalues are ignored in the averaging. A results figure is also requested using the fig option.

Example 3 - Construct synthetic control group:synth cigsale retprice cigsale(1970) cigsale(1979) , trunit(33) counit(1(1)20) trperiod(1980) figresultsperiod(1970(1)1990)

In this example, the unit affected by the intervention is state no 33, and the donor pool of potentialcontrol units is restricted to states no 1,2,...,20. The intervention occurs in 1980, and results areobtained for the 1970,1971,...,1990 period.

Example 4 - Construct synthetic control group:synth cigsale retprice cigsale(1970) cigsale(1979) , trunit(33) counit(1(1)20) trperiod(1980)resultsperiod(1970(1)1990) keep(resout)

This example is similar to example 2 but keep(resout) is specified and thus synth will save a datasetnamed resout.dta in the current Stata working directory (type pwd to see the path of your workingdirectory). This dataset contains the result from the current fit and can be used for furtherprocessing. Also to easily access results recall that synth routinely returns all result matrices. Thesecan be displayed by typing ereturn list after synth has terminated.

Example 5 - Construct synthetic control group:synth cigsale beer lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975) , trunit(3)trperiod(1989) xperiod(1980(1)1988) nested

This is again example 2, but the nested option is specified, which typically produces a better fit atthe expense of additional computing time. Alternativley, the user can also specified the allopt optionwhich can improve the fit even further and requires yet more computing time. Also, xperiod isspecified indicating that predictors are averaged for the 1980,1981,...,1988 period.

Example 5 Run placebo in space::. tempname resmatforvalues i = 1/4 {synth cigsale retprice cigsale(1988) cigsale(1980) cigsale(1975) , trunit(`i') trperiod(1989)xperiod(1980(1)1988)matrix `resmat' = nullmat(`resmat') \ e(RMSPE)local names `"`names' `"`i'"'"'}mat colnames `resmat' = "RMSPE"mat rownames `resmat' = `names'matlist `resmat' , row("Treated Unit")

This is a code example to run placebo studies by iteratively reassigning the intervention in space tothe first four states. To do so, we simply run a four loop each where the trunit setting isincremented in each iteration. Thus, in the n of synth state number one is assigned to the intervention,in the second run state number two, etc, etc. In each run we store the RMSPE and display it in a matrixat the end.

第二部分:

【1分钟计量】倾向匹配得分do文档讲义

*-------------------------------------------------------------------------------# 倾向匹配得分 *-------------------------------------------------------------------------------*1、外部命令配置sscinstall psmatch2finditpsmatch2helppsmatch2

helpnnmatchhelppsmatchhelppscore

finditpropensity scorefinditmatching

sscinstall psmatch2, replacewhichpsmatch2whichado

*2、范例数据use"ldw_exper.dta", clear eddesc

*3、描述性分析tabulatet, summarize(re78) means standard

*4、回归分析setseed 20180105 //产生随机数种子 genu=runiform sortu //排序 *或者orderu

*5、倾向匹配得分localv1 "t"localv2 "age edu black hisp married re74 re75 u74 u75"globalx "`v1' `v2' "

psmatch2$x, out(re78) neighbor(1) ate ties logit common // 1:1 匹配$表示引用宏变量,*等价于psmatch2t age edu black hisp married re74 re75 u74 u75, out(re78) neighbor(1) ate ties logit common

*6、均衡性检验pstest$v2, both graph

*7、共同取值范围psgraph

*8、最近邻匹配,k= 4psmatch2$x, out(re78) n(4) ate ties logit common

*9、计算倾向得分sum_pscore

*10、半径匹配psmatch2$x, out(re78) n(4) cal(0.01) ate ties logit common

*11、核匹配,使用默认的核函数和带宽psmatch2$x, out(re78) kernel ate ties logit common quietly

*-------------------------------------------------------------------------------*计量经济学服务中心*-------------------------------------------------------------------------------

第三部分

Stata命令模板*断点回归分析设计

*========================================* 高级计量经济学*========================================* 计量经济学服务中心

*------------------------------------------------------------------------------- * 参考资料:* 《初级计量经济学及 Stata应用: Stata从入门到进阶》 * 《高级计量经济学及 Stata应用: Stata回归分析与应用》 * 《高级计量经济学及 Eviews应用》 * 《空间计量入门》 * 《零基础|轻松搞定空间计量:空间计量及 GeoDa、 Stata应用》 * 《空间计量第二部:空间计量及 Matlab应用课程》 * 《空间计量第三部:空间计量及 Stata应用课程》 * 《空间计量第四部:《空间计量及 ArcGis应用课程》 * 《空间计量第五部:空间计量经济学》* 《空间计量第六部:《空间计量及 Python应用》 * 《空间计量第七部:《空间计量及 R应用》 * 《空间计量第八部:《高级空间计量经济学》*-------------------------------------------------------------------------------

*-------------------------------------------------------------------------------* RD断点回归分析设计 *-------------------------------------------------------------------------------

adopath + E:\stata\plus2 adopath + E:\stata\plus

* 1、数据查看 cd E:\stata\data use rdrobust_senate.dta, cleareddesc

* 2、断点图形分析 * 2.1查看在断点处是否连续 * binscatterbinscatter vote margin,rd( 0) n( 50) linetype(lfit) ///xtitle( "Vote Share in Election at time t") ///ytitle( "Vote Share in Election at time t+2")

binscatter vote margin ifmargin>- 50& margin< 50, ///rd( 0) n( 50) linetype(lfit) ///xtitle( "Vote Share in Election at time t") ///ytitle( "Vote Share in Election at time t+2") * 2.2、cmogram

cmogram vote margin ifmargin>- 50& margin< 50, ///scatter cut( 0) lineat( 0) lfit ci( 95) histopts(bin( 25))

* 2.3、twoway graph

tw (scatter vote margin ifmargin>- 50& margin< 50) ///(lfit vote margin ifmargin>- 50& margin< 0) ///(lfit vote margin ifmargin>= 0& margin< 50, ///xline( 0,lc(red)) legend(off) ///xtitle( "Vote Share in Election at time t") ///ytitle( "Vote Share in Election at time t+2"))

* 2.4、rdplot rdplot vote margin, c( 0) p( 4) binselect(es) ci( 95) ///graph_options(title( "RD Plot: U.S. Senate Election Data") ///ytitle( VoteShareinElectionat time t+ 2) ///xtitle( VoteShareinElectionat time t) ///graphregion(color(white)))

rdplot vote margin ifmargin>- 50& margin< 50, c( 0) p( 2) binselect(es) ci( 95) ///graph_options(title( "RD Plot: U.S. Senate Election Data") ///ytitle( VoteShareinElectionat time t+ 2) ///xtitle( VoteShareinElectionat time t) ///graphregion(color(white)))* 3.检验内生分组 DCdensitymargin,breakpoint( 0) generate( XjYjr0 fhat se_fhat)

* 4、其他协变量连续检验 cmogram population margin ifmargin>- 50& margin< 50, ///scatter cut( 0) lineat( 0) qfit ci( 95) histopts(bin( 20))

* 5、断点回归分析设计 g D= margin> 0// generate treatment statusg marginsq = margin*marging D_margin= D*margin

reg vote Dmargin reg vote Dmargin marginsq

reg vote Dmargin D_margin

rdrobust vote margin

reg vote Dmargin ifmargin>- 17& margin< 17reg vote Dmargin D_marginifmargin>- 17& margin< 17返回搜狐,查看更多



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有